"use strict";
cc._RF.push(module, 'b323bkuEUxGJZnlnRmZg9jj', 'ModeBtn');
// scripts/Game/Obj/ModeBtn.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameConfig_1 = require("../../engines/configs/gameConfig");
var gameEngine_1 = require("../../engines/gameEngine");
var node_component_1 = require("../../engines/libs/node_component");
var gameMode_json_1 = require("../../engines/managers/gameContent/gameMode_json");
var userInterface_1 = require("../../engines/services/userContent/userInterface");
var Const_1 = require("../Const");
var Enum_1 = require("../Enum");
var MainRoot_1 = require("../MainRoot");
// const Mode = cc.Enum({
//     NORMAL: 0,
//     MATCHEQUATION: 1,// 移火柴模式
//     CHANGEONEMODE: 2,// 改一笔变字
//     CHARPUZZLE: 3,// 拼字
//     DRAW_LINE_PROTECTED: 4,// 画线保护小人
//     ONE_DRAW: 5,// 一笔画完
//     RED_BLOCK: 6,// 解锁红木
//     DRAG_BLOCK: 7,// 抽积木
//     CORE_BALL: 8,
//     PUSH_BOX: 9,//推箱子
//     GUSS_PLACE: 10,
//     SUROUND: 11,
//     PINZI: 12,
//     FIGHTMODE: 13,
//     FINDWORD: 14,
//     FANTASTIC: 16,//奇思妙想
//     IQ_COMPUTE: 17,//细节计算
//     CONNECT: 18,//连线挑战
//     WONDERFUL: 100,
//     WONDERFUL2: 101
// });
var Mode = cc.Enum(gameMode_json_1.GAME_MODE);
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, menu = _a.menu, disallowMultiple = _a.disallowMultiple;
var ModeBtn = /** @class */ (function (_super) {
    __extends(ModeBtn, _super);
    function ModeBtn() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.isOutBtn = false;
        _this.m_mode = Mode.NORMAL;
        _this.contentImg = null;
        _this.titleImg = null;
        _this.AdProgress = null;
        _this.AdIcon = null;
        _this.levelProgress = null;
        _this.autoWidge = false;
        return _this;
    }
    ModeBtn.prototype.BtnInit = function (mode) {
        this.m_mode = mode;
    };
    ModeBtn.prototype.onLoad = function () {
        return __awaiter(this, void 0, void 0, function () {
            var imgPair;
            var _this = this;
            return __generator(this, function (_a) {
                imgPair = MainRoot_1.default.ConfigSerive.ModeImgMap[this.m_mode];
                try {
                    node_component_1.default.loadResourcesPicture("Img/Mode/" + imgPair.titleImg + (this.isOutBtn ? "O" : ""), this.titleImg);
                    node_component_1.default
                        .loadResourcesPicture("Img/Mode/" + imgPair.contentImg + (this.isOutBtn ? "O" : ""), this.contentImg)
                        .then(function (spriteF) {
                        if (_this.autoWidge) {
                            _this.contentImg.node.y =
                                (spriteF.getOriginalSize().height - _this.node.height) * 0.5;
                        }
                    });
                }
                catch (e) { }
                this.RefreshInfo();
                return [2 /*return*/];
            });
        });
    };
    ModeBtn.prototype.OnEnterBtn = function (event, custom) {
        var _this = this;
        gameEngine_1.managers().soundMgr.playSound("mainSound/anNiu");
        var type = Number(custom);
        var mode = this.m_mode;
        // console.log("包名");
        var completeFun = type
            ? function () { return __awaiter(_this, void 0, void 0, function () {
                var bundleName;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            console.info("bundleName", mode);
                            console.warn('重置3');
                            MainRoot_1.default.GotTips = false;
                            MainRoot_1.default.GotAnswer = false;
                            bundleName = MainRoot_1.default.LevelSystem.GetSignleLevelInfo(mode).bundleName;
                            // services().userSrv.setPower(-gameConfig.MODE_POWER[mode], true, true);
                            return [4 /*yield*/, MainRoot_1.default.LevelSystem.LoadLevel(bundleName, mode)];
                        case 1:
                            // services().userSrv.setPower(-gameConfig.MODE_POWER[mode], true, true);
                            _a.sent();
                            MainRoot_1.default.UISystem.ClosePage(Enum_1.PAGE.MODEMENU);
                            return [2 /*return*/];
                    }
                });
            }); }
            : function () {
                var levelMenuPrams = {
                    mode: mode,
                };
                // if(mode == Mode.BHMB||mode == Mode.CJTT){
                //   mainRoot.UISystem.OpenPage(PAGE.LEVELSKINMENU, levelMenuPrams);
                // }else{
                MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.LEVELMENU, levelMenuPrams);
                // }
            };
        if (!gameEngine_1.services().userSrv.getModeUnlocked(this.m_mode)) { //如果没解锁
            gameEngine_1.services()
                .miniGameSrv.getAppApiInstance()
                .loadAndShowVideoAd(function () {
                gameEngine_1.services().userSrv.addModeAdCount(_this.m_mode);
            }, function (e) {
                console.error(e);
            }, function () {
                if (gameEngine_1.services().userSrv.getModeAdCount(_this.m_mode) >=
                    gameConfig_1.default.MODE_VIDEO_COUNT[_this.m_mode]) {
                    gameEngine_1.services().userSrv.UnlockMode(_this.m_mode);
                    completeFun();
                }
                _this.RefreshInfo();
            }, "\u770B\u5E7F\u544A\u89E3\u9501" + Const_1.MODE_NAME_MAP[this.m_mode]);
            return;
        }
        if (gameEngine_1.services().userSrv.getPower() - gameConfig_1.default.MODE_POWER[mode] < 0) {
            gameEngine_1.modules().uiControlModule.showUserPropGet(userInterface_1.REWARD_TYPE.POWER, gameConfig_1.default.ADD_ONCE_POWER);
            return;
        }
        gameEngine_1.services().userSrv.setPower(-gameConfig_1.default.MODE_POWER[mode], true, true);
        completeFun();
    };
    ModeBtn.prototype.RefreshInfo = function () {
        // console.log("刷新模式按钮",this.m_mode,services().userSrv.getModeAdCount(this.m_mode));
        this.AdProgress.node.active = !gameEngine_1.services().userSrv.getModeUnlocked(this.m_mode);
        this.AdProgress.string = gameEngine_1.services().userSrv.getModeAdCount(this.m_mode) + ":" + gameConfig_1.default.MODE_VIDEO_COUNT[this.m_mode];
        this.AdIcon.active = !gameEngine_1.services().userSrv.getModeUnlocked(this.m_mode);
        if (this.levelProgress) {
            this.levelProgress.string = MainRoot_1.default.LevelSystem.GetFarLevel(this.m_mode) + ":" + MainRoot_1.default.LevelSystem.GetMaxLevel(this.m_mode);
        }
    };
    __decorate([
        property({ displayName: "是否为在外面展示的按钮" })
    ], ModeBtn.prototype, "isOutBtn", void 0);
    __decorate([
        property({ type: Mode, displayName: "对应的模式" })
    ], ModeBtn.prototype, "m_mode", void 0);
    __decorate([
        property({ type: cc.Sprite, displayName: "模式内容展示的图标" })
    ], ModeBtn.prototype, "contentImg", void 0);
    __decorate([
        property({ type: cc.Sprite, displayName: "模式标题的图标" })
    ], ModeBtn.prototype, "titleImg", void 0);
    __decorate([
        property({ type: cc.Label, displayName: "广告进度" })
    ], ModeBtn.prototype, "AdProgress", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "广告图标" })
    ], ModeBtn.prototype, "AdIcon", void 0);
    __decorate([
        property({ type: cc.Label, displayName: "关卡进度" })
    ], ModeBtn.prototype, "levelProgress", void 0);
    __decorate([
        property({ displayName: "是否自动对齐内容图标" })
    ], ModeBtn.prototype, "autoWidge", void 0);
    ModeBtn = __decorate([
        ccclass,
        menu("工具组件/模式按钮")
    ], ModeBtn);
    return ModeBtn;
}(cc.Component));
exports.default = ModeBtn;

cc._RF.pop();